package com.bretagne5.radio;

import java.util.Locale;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerTitleStrip;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bretagne5.radio.utils.AlertDialogConnection;


public class MainActivity extends FragmentActivity    {

	SectionsPagerAdapter mSectionsPagerAdapter;
	ViewPager mViewPager;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		PagerTitleStrip pagerTitleStrip = (PagerTitleStrip) findViewById(R.id.pager_title_strip);
		pagerTitleStrip.setBackgroundColor(getResources().getColor(R.color.bar));
		
		mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

		mViewPager = (ViewPager) findViewById(R.id.pager);
		mViewPager.setAdapter(mSectionsPagerAdapter);
		
	}
	
	
	@Override
	protected void onStart() {
		super.onStart();
		
		AlertDialogConnection dialogConnection = new AlertDialogConnection(this); 
		 	 
	}

	public class SectionsPagerAdapter extends FragmentPagerAdapter {

		public SectionsPagerAdapter(android.support.v4.app.FragmentManager fm) {
			super(fm);
		}

		@Override
		public android.support.v4.app.Fragment getItem(int position) {
			switch (position) {
			case 0:
				
				return new RadioFragment();
			}
			return null;
		}

		@Override
		public int getCount() {
			
			return 1;
		}

		@Override
		public CharSequence getPageTitle(int position) {
			Locale l = Locale.getDefault();
			switch (position) {
			case 0:
				return "Radio";
			}
			return null;
		}
	}


	public static class DummySectionFragment extends android.support.v4.app.Fragment {

		public static final String ARG_SECTION_NUMBER = "section_number";

		public DummySectionFragment() {
		}

		@Override
		public View onCreateView(LayoutInflater inflater, ViewGroup container,
				Bundle savedInstanceState) {
			View rootView = inflater.inflate(R.layout.fragment_main_dummy,
					container, false);
			TextView dummyTextView = (TextView) rootView
					.findViewById(R.id.section_label);
			dummyTextView.setText(Integer.toString(getArguments().getInt(
					ARG_SECTION_NUMBER)));
			return rootView;
		}
	}
	
	/**
	 * 
	 * Menu
	 * 
	 * 
	 */
	
	public boolean onCreateOptionsMenu(Menu menu) {
	    MenuInflater inflater = getMenuInflater();
	    inflater.inflate(R.menu.menu_radio, menu);
	    return true;
	}
	
	public boolean onOptionsItemSelected(MenuItem item) {
	    switch (item.getItemId()) {
	        case R.id.Programme :
	        	
	        	Intent IntentPreferences = new Intent(getApplicationContext(),ProgrammeFragActivity.class);
				startActivity(IntentPreferences);
				
	            return true;
	            
	        case R.id.reseaux_sociaux :
	        	
	        	Intent intentSociaux = new Intent(getApplicationContext(),ReseauxSociaux.class);
				startActivity(intentSociaux);
				
	            return true;
	            
	        default:
	            return super.onOptionsItemSelected(item);
	    }
	}

}
